﻿//  --------------------------------
//  Copyright (c) 2010 Michael Schuler, Sascha Burger. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://p2pmessaging.codeplex.com/license
//  ---------------------------------
using NUnit.Framework;
using p2pMessaging.BL.Model;
using p2pMessaging.Interfaces.Contact;

namespace p2pMessaging.Tests
{
	[TestFixture]
	public class ContactTest
	{
		private IContact myParent;
		private IContact myChild;

		[SetUp]
		public void SetUp()
		{
			myParent = new Contact();
			myChild = new Contact();
			
			myParent.Children.Add(myChild);
			myParent.City = "Oberwinterthur";
			myParent.EmailAddress = "parent@test.local";
			myParent.FirstName = "Parent";
			myParent.IpAddress = "127.0.0.1";
			myParent.LastName = "PName";
			myParent.Street = "Frauenfelderstrasse";
			myParent.ZipCode = "8404";

			myChild.City = "Winterthur Hegi";
			myChild.EmailAddress = "child@test.local";
			myChild.FirstName = "Child";
			myChild.IpAddress = "127.0.0.2";
			myChild.LastName = "CName";
			myChild.Parent = myParent;
			myChild.Street = "Im oberen Gern";
			myChild.ZipCode = "8409";
		}
		
		[Test]
		public void TestInheritance()
		{
			Assert.AreEqual("Child", myChild.FirstName);
			Assert.AreEqual("CName", myChild.LastName);
			Assert.AreEqual("Winterthur Hegi", myChild.City);
			Assert.AreEqual("child@test.local", myChild.EmailAddress);
			Assert.AreEqual("127.0.0.2", myChild.IpAddress);
			Assert.AreEqual("Im oberen Gern", myChild.Street);
			Assert.AreEqual("8409", myChild.ZipCode);

			myChild.City = null;
			myChild.EmailAddress = null;
			myChild.FirstName = null;
			myChild.IpAddress = null;
			myChild.LastName = null;
			myChild.Street = null;
			myChild.ZipCode = null;

			Assert.AreEqual(string.Empty, myChild.FirstName);
			Assert.AreEqual(string.Empty, myChild.LastName);
			Assert.AreEqual(myParent.City, myChild.City);
			Assert.AreEqual(myParent.EmailAddress, myChild.EmailAddress);
			Assert.AreEqual(myParent.IpAddress, myChild.IpAddress);
			Assert.AreEqual(myParent.Street, myChild.Street);
			Assert.AreEqual(myParent.ZipCode, myChild.ZipCode);
			
			Assert.AreEqual(myChild, myParent.Children[0]);
			Assert.IsTrue(myParent.Equals(myChild.Parent));
			Assert.IsFalse(myParent.Equals(null));

			Assert.AreNotEqual(0, myParent.GetHashCode());

			myParent.Id = string.Empty;

			Assert.AreEqual(1, myParent.CompareTo(myChild));
			Assert.AreNotEqual(0, myParent.GetHashCode());
		}
	}
}
